﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyDoanVien.Bussiness;
using QuanLyDoanVien.Controller;
using QuanLyDoanVien.General;
using DevComponents.DotNetBar;

namespace QuanLyDoanVien
{
    public partial class frmChuyenLop : Form
    {
        LopCtrl m_LopDi_Ctrl = new LopCtrl();
        LopCtrl m_LopDen_Ctrl = new LopCtrl();
        List<HocSinhInfo> ds_hs = new List<HocSinhInfo>();
        HocSinhCtrl m_HocSinhCtrl = new HocSinhCtrl();

        public frmChuyenLop()
        {
            InitializeComponent();
            DataService.OpenConnection();
        }

        private bool Check_HocSinh_RaTruong(String malop)
        {
            ds_hs = m_HocSinhCtrl.layHocSinhTheoLop(malop);
            if (ds_hs.Count > 0)
            {
                return true;
            }
            return false;
        }
        private void Load_DS_Lop(String malop)
        {
            ds_hs = m_HocSinhCtrl.layHocSinhTheoLop(malop);
            this.dataGridView_HS_Lop.Rows.Clear();
            foreach (HocSinhInfo hs in ds_hs)
            {
                dataGridView_HS_Lop.Rows.Add(hs.MaHocSinh,hs.HoTen,hs.MaLop,hs.GioiTinh,hs.NgaySinh,hs.NoiSinh,hs.NgayVaoDoan,hs.MaChucVu,hs.HoTenCha,hs.HoTenMe);
            }
        }
        private void frmChuyenLop_Load(object sender, EventArgs e)
        {
            
            m_LopDi_Ctrl.HienThiComboBox(this.cmb_LopDi);
            m_LopDen_Ctrl.HienThiComboBox(this.cmb_LopDen);
            Load_DS_Lop(this.cmb_LopDi.SelectedValue.ToString());
        }

        private void cmb_LopDi_SelectedIndexChanged(object sender, EventArgs e)
        {
            Load_DS_Lop(this.cmb_LopDi.SelectedValue.ToString());
        }

        private void btn_HS_Chuyen_Click(object sender, EventArgs e)
        {
            if (Check_HocSinh_RaTruong(this.cmb_LopDen.SelectedValue.ToString()) == true)
            {
                MessageBoxEx.Show("Lớp Chuyển Tới Vẫn Chưa Đánh Dấu Ra Trường", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            MessageBoxEx.Show("Chuyển Lớp thành công", "Thông báo");
            m_HocSinhCtrl.ChuyenHocSinh(this.cmb_LopDi.SelectedValue.ToString(), this.cmb_LopDen.SelectedValue.ToString());
            Load_DS_Lop(this.cmb_LopDi.SelectedValue.ToString());


        }

        private void cmb_LopDen_SelectedIndexChanged(object sender, EventArgs e)
        {
            Load_DS_Lop(this.cmb_LopDen.SelectedValue.ToString());
        }
    }
}
